<template>
    <div class="qingwu">
        <div class="admin_table_page_title">财务记录</div>
        <div class="unline underm"></div>

        <div class="admin_table_list">
            <a-table :columns="columns" :data-source="list" :pagination="false" :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" row-key="id">



                <div slot="userdata" slot-scope="rows">
                    <p>姓名: {{rows.community_data ? rows.community_data.username :""}}</p>
                    <p>手机号: {{rows.community_data ? rows.community_data.mobile :""}}</p>
                </div>
                <div slot="money_type" slot-scope="rows">
                    <span v-if="rows.pay_type == 1" class="layui-badge layui-bg-blue">微信缴费</span>
                    <span v-else-if="rows.pay_type == 2" class="layui-badge layui-bg-blue">支付宝缴费</span>
                    <span v-else-if="rows.pay_type == 4" class="layui-badge layui-bg-orange">余额扣款</span>
                </div>

                <div slot="capital_uses" slot-scope="rows">
                    <span v-if="rows.type == 1" class="layui-badge layui-bg-blue">电费</span>
                    <span v-else-if="rows.type == 2" class="layui-badge layui-bg-blue">水费</span>
                    <span v-else-if="rows.type == 3" class="layui-badge layui-bg-orange">物业费</span>
                </div>

                <div slot="balancedata" slot-scope="rows">
                    <p>账单金额: <span>{{rows.bill_balance}}</span></p>
                    <p>交易前<span v-if="rows.type == 1">电费</span>
                        <span v-else-if="rows.type == 2">水费</span>
                        <span v-else-if="rows.type == 3">物业费</span>余额: {{rows.before_balance}}</p>
                    <p>交易后<span v-if="rows.type == 1">电费</span>
                        <span v-else-if="rows.type == 2">水费</span>
                        <span v-else-if="rows.type == 3">物业费</span>余额: {{rows.after_balance}}</p>
                </div>

                <span slot="status" slot-scope="rows">
                    <a-switch v-if="rows.status == 1" checked-children="正常" un-checked-children="禁用" @change="onChangeStatus(rows.id)" default-checked/>
                    <a-switch v-else checked-children="正常" @change="onChangeStatus(rows.id)" un-checked-children="禁用" />
                </span>
            </a-table>
            <div class="admin_pagination" v-if="total>0">
                <a-pagination v-model="params.page" :page-size.sync="params.per_page" :total="total" @change="onChange" show-less-items />
            </div>
        </div>
    </div>
</template>

<script>
export default {
    components: {},
    props: {},
    data() {
      return {
          params:{
              page:1,
              per_page:30,
          },
          total:0, //总页数
          selectedRowKeys:[], // 被选择的行
          columns:[
              {title:'#',dataIndex:'id',fixed:'left'},
              {title:'用户信息',scopedSlots: { customRender: 'userdata' }},
              {title:'资金类型',scopedSlots: { customRender: 'money_type' }},
              {title:'资金用途',scopedSlots: { customRender: 'capital_uses' }},
              {title:'账单金额',scopedSlots: { customRender: 'balancedata' }},
              {title: '订单号', dataIndex:'order_num'},
              {title:'创建时间',dataIndex:'create_time'},
              // {title:'操作',key:'id',fixed:'right',scopedSlots: { customRender: 'action' }},
          ],
          list:[],
          username:'',  // 名称
          phone:'',     // 手机号
          community_id:'',   // 小区ID
          community_lists: []
      };
    },
    watch: {},
    computed: {},
    methods: {
        // 选择框被点击
        onSelectChange(selectedRowKeys) {
            this.selectedRowKeys = selectedRowKeys;
        },
        // 选择分页
        onChange(e){
            this.params.page = e;
            this.onload();
        },
        // 修改状态
        onChangeStatus(id){
            this.$post(this.$api.editUserStatus,{id:id}).then(res=>{
                if(res.code == 200){
                    this.$message.success(res.msg)
                }else{
                    return this.$message.error(res.msg)
                }
            })
        },
        // 删除
        del(){
            if(this.selectedRowKeys.length==0){
                return this.$message.error('未选择数据.');
            }
            this.$confirm({
                title: '你确定要删除选择的数据？',
                content: '确定删除后无法恢复.',
                okText: '是',
                okType: 'danger',
                cancelText: '取消',
                onOk:()=> {
                    let ids = this.selectedRowKeys.join(',');
                    this.$delete(this.$api.adminUsers+'/'+ids).then(res=>{
                        if(res.code == 200){
                            this.onload();
                            this.$message.success('删除成功');
                        }else{
                            this.$message.error(res.msg)
                        }
                    });

                },
            });
        },
        onload(){
            this.$get(this.$api.estateAccounts,this.params).then(res=>{
                this.total = res.data.total;
                this.list = res.data.data;
            });
        },
        // 重置
        reset(){
            location.reload();
        },
        // 获取小区列表
        // getCommunityList(){
        //     this.$get(this.$api.adminCommunity).then(res=>{
        //         this.community_lists = res.data.data;
        //     })
        // },
        // 搜索
        search(){
            this.params['username'] = this.username;
            this.params['phone'] = this.phone;
            this.params['community_id'] = this.community_id;
            this.$get(this.$api.adminUsers,this.params).then(res=>{
                this.total = res.data.total;
                this.list = res.data.data;
            });
        },
    },
    created() {
        this.onload();
        // this.getCommunityList();/**/
    },
    mounted() {}
};
</script>
<style lang="scss" scoped>

</style>
